﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;
using System.Windows.Markup;

namespace SteamGroupPlayers.Utilities.Converters
{
    [ValueConversion( typeof(IEnumerable<object>), typeof(bool) )]
    class HasItemsToBoolConverter : MarkupExtension, IValueConverter
    {
        #region Fields
        private static HasItemsToBoolConverter _instance;
        #endregion

        #region Methods
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return _instance ?? (_instance = new HasItemsToBoolConverter());
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is IEnumerable<object>))
                return false;

            return (value as IEnumerable<object>).Count() > 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
        #endregion
    }
}
